package com.znf4.config;

import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * mq设置型配置
 */

public class MqConfig {

	private static final Log LOG = LogFactory.getLog(MqConfig.class);

	/** 代付目的地 **/
	public static String PROXY_PAY_QUERY_QUEUE = "";

	/** 支付结果队列地址 **/
	public static String PAY_RESULT_NOTIFY_QUEUE = "";

	/**
	 * 只加载一次.
	 */
	static {
		try {
			LOG.info("=== load mq.properties and init sys param");
			InputStream proFile = Thread.currentThread().getContextClassLoader().getResourceAsStream("mq_config.properties");
			Properties props = new Properties();
			props.load(proFile);
			init(props);
		} catch (Exception e) {
			LOG.error("=== load and init mq exception:" + e);
		}
	}

	/**
	 * 根据配置文件初始化静态变量值.
	 * 
	 * @param props
	 */
	private static void init(Properties props) {
		String proxyPayQueueName = props.getProperty("proxyPayQueueName.query");
		if (StringUtils.isNotBlank(proxyPayQueueName)) {
			PROXY_PAY_QUERY_QUEUE = proxyPayQueueName;
		} else {
			throw new RuntimeException("代付mq queue为空");
		}

		String payResultNotifyQueue = props.getProperty("tradeQueueName.notify");
		if (StringUtils.isNotBlank(payResultNotifyQueue)) {
			PAY_RESULT_NOTIFY_QUEUE = payResultNotifyQueue;
		} else {
			throw new RuntimeException("代付mq queue为空");
		}
	}

}
